﻿// ***********************************************************************
// Apache 2.0 License
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
//
// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY 
// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR 
// PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
//
// See the Apache Version 2.0 License for specific language governing
// permissions and limitations under the License.
// ***********************************************************************
// Assembly  : ContractMeow.Models
// File      : PraiseAttachmentModel.cs
//
// ***********************************************************************
using System.Collections.Generic;


namespace ContractMeow.Models.Attachments
{
	public class PraiseAttachmentModel : AttachmentModel, IPraiseAttachmentModel
	{
		private static readonly double _verticalOffset = 46.0;//in pixels

		private static readonly Dictionary<string, double> _iconSelector = new Dictionary<string, double>()
			{
				{"star", 0.0},
				{"thumbsup", 1.0},
				{"trophy", 2.0},
				{"checkeredflag", 3.0},
				{"lightbulb", 4.0},
				{"graduationcap", 5.0},
				{"money", 6.0},
				{"ace", 7.0},
				{"glasses", 8.0},
				{"heart", 9.0},
				{"doublerainbow", 10.0},
				{"coffee", 11.0},
				{"pie", 12.0},
				{"diamond", 13.0},
				{"monocle", 14.0}, //(mustache)
				{"ninja", 15.0},
				{"gift", 16.0},
			};

		public static IPraiseAttachmentModel FromIAttachment(ContractMeow.Api.Dtos.Attachment.IPraiseAttachment attachment)
		{
			return new PraiseAttachmentModel(attachment);
		}

		internal PraiseAttachmentModel(ContractMeow.Api.Dtos.Attachment.IPraiseAttachment praiseAttachment) :
			base(praiseAttachment)
		{
			PraisedUserIds = new List<long>(praiseAttachment.PraisedUserIds);
			Comment = praiseAttachment.Comment;
			IconName = praiseAttachment.IconName;
		}

		public List<long> PraisedUserIds { get; set; }
		public string Comment { get; set; }

		public string SpriteUrl
		{
			get { return "https://www.yammer.com/images/platform/praise/badges-white-bg.jpg"; }
		}

		public double OffsetY
		{
			get
			{
				double offset = 0;
				var xCoord = 0.0;
				// gift -2
				// ninja -1
				// glasses, money +1
				// graduationcap, lightbulb, checkeredflag, trophy, star, thumbsup +2
				if (_iconSelector.TryGetValue(IconName, out xCoord))
				{
					if (xCoord < 7.0)
					{

						offset = (xCoord == 1.0 || xCoord == 2.0)
									 ? 3.0
									 : 2.0;
					}
					else if (xCoord < 9.0)
						offset = 1.0;
					else if (xCoord < 14)
						offset = 0.0;
					else if (xCoord < 15)
						offset = -1.0;
					else
						offset = -2;
				}
				else
					xCoord = 0.0;
				return -(_verticalOffset * xCoord + offset);//invert offset (sprites go downwards)
			}
		}

		public string Names { get; set; }

		public string IconName { get; set; }

	}
}
